package com.nenu.bdms.controller;

import com.nenu.bdms.config.webresult.WebResult;
import com.nenu.bdms.module.subexperiment.SubExperimentVO;
import com.nenu.bdms.module.test.EXVO;
import com.nenu.bdms.module.test.RecordVO;
import com.nenu.bdms.service.RecordService;
import com.nenu.bdms.service.GetConfigService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "test", description = "测试接口")
@RequestMapping("/test")
@RestController
@CrossOrigin
public class ExperimentImplementController {
    @Autowired
    GetConfigService testService;
    @Autowired
    RecordService recordService;


    @GetMapping("/getTestId")
    @Operation(summary = "用于测试系统接口")
    public WebResult getTestId(){
        return testService.getTestId();
    }

    @PostMapping("/verifyTesteeInfoAndGetExperimentConfig")
    public WebResult VerifyTesteeInfoAndGetExperimentConfig (@RequestBody EXVO exvo) {
        Integer testeeId = exvo.getTesteeId();
        String seatSno = exvo.getSeatSno();
        return testService.getAllData(testeeId,seatSno);
    }

    @PostMapping("/saveExperimentResult")
    public WebResult SaveExperimentResult (@RequestBody RecordVO recordVO) {
        Integer experimentId = recordVO.getExperimentId();
        System.out.println(experimentId);
        Integer testeeId = recordVO.getTesteeId();
        List<SubExperimentVO> subExperimentVOList = recordVO.getSubExperiment();
        recordService.saveAllData(experimentId,subExperimentVOList);
        return recordService.updateStatus(experimentId,testeeId);
    }


}
